﻿using KAKA.Domain;
using KAKA.Repository;
using Morus;
using System.Web;
using System.Web.Mvc;
using System.Linq;

namespace KAKA
{
    public class NicknameAttribute : FilterAttribute, IResultFilter
    {
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {

        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var httpContext = filterContext.HttpContext;

            if (httpContext.User.Identity.IsAuthenticated)
            {
                User user = httpContext.Items[typeof(User)] as User;

                httpContext.Items[typeof(Member)] = user.Member.Nickname;
                httpContext.Items[typeof(Message)] = user.Notifications.Count(r => r.Read == false);
            }
        }
    }
}